import java.util.Scanner;

public class SafeHomeControlPanel {

    enum State {
        IDLE, INPUTTING_PASSWORD, PASSWORD_CORRECT, PASSWORD_INCORRECT, LOCKED, UNLOCKING
    }

    private State currentState = State.IDLE;
    private int wrongAttempts = 0;
    private final String correctPassword = "666666"; // 初始密码
    private final Scanner scanner = new Scanner(System.in);
    private long lockTime = 0;

    public void run() {
        while (true) {
            switch (currentState) {
                case IDLE:
                    System.out.println("系统空闲，等待输入密码...（初始密码设置666666）");
                    currentState = State.INPUTTING_PASSWORD;
                    break;

                case INPUTTING_PASSWORD:
                    System.out.print("请输入密码: ");
                    String inputPassword = scanner.nextLine();
                    if (inputPassword.equals(correctPassword)) {
                        currentState = State.PASSWORD_CORRECT;
                    } else {
                        wrongAttempts++;
                        if (wrongAttempts >= 3) {
                            currentState = State.LOCKED;
                            lockTime = System.currentTimeMillis();
                        } else {
                            currentState = State.PASSWORD_INCORRECT;
                        }
                    }
                    break;

                case PASSWORD_CORRECT:
                    System.out.println("密码正确，进入系统功能...");
                    // 这里可以添加系统功能的逻辑
                    currentState = State.IDLE;  // 任务完成，进入空闲状态
                    break;

                case PASSWORD_INCORRECT:
                    System.out.println("密码错误，剩余尝试次数：" + (3 - wrongAttempts));
                    currentState = State.INPUTTING_PASSWORD;  // 继续输入密码
                    break;

                case LOCKED:
                    long elapsedTime = (System.currentTimeMillis() - lockTime) / 1000; // 锁定时间已过的秒数
                    if (elapsedTime >= 120) {
                        System.out.println("锁定解除，重新输入密码...");
                        currentState = State.UNLOCKING;
                    } else {
                        System.out.println("密码错误3次，系统锁定中... 请稍等 " + (120 - elapsedTime) + " 秒");
                    }
                    break;

                case UNLOCKING:
                    wrongAttempts = 0;  // 锁定解除后重置错误次数
                    currentState = State.INPUTTING_PASSWORD;  // 重新输入密码
                    break;
            }

            try {
                Thread.sleep(1000); // 每秒钟检查一次状态
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        SafeHomeControlPanel controlPanel = new SafeHomeControlPanel();
        controlPanel.run();
    }
}
